# -*- coding: utf-8 -*-
"""Helper utilities and decorators."""

import os
import sys
import hashlib


def excludes_format(path, excludes_string=None):
    """
    排除文件，支持正则匹配，支持多选字符串
    @param path:
    @param excludes_string:
    @return:
    """
    path = os.path.basename(path) + '/'
    if not excludes_string:
        return path

    prefix = '--exclude='
    excludes = [prefix + i for i in excludes_string.split('\n') if i.strip()]
    return ' {excludes} {path} '.format(excludes=' '.join(excludes), path=path)


def includes_format(path, includes_string=None):
    """
    指定发布文件，支持正则匹配，如：*.war。支持多行字符串。

    @param path: release目录，非路径
    @param includes_string:
    @return:
    """
    path = os.path.basename(path) + '/'
    if not includes_string:
        return path

    prefix = path
    includes = [prefix + i for i in includes_string.split('\n') if i.strip()]

    if not includes:
        return path

    return ' '.join(includes)


def mkdir(path):
    is_exists = os.path.exists(path)
    if not is_exists:
        os.makedirs(path)
